home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
dirut
/
rh_ls.zip
/
LS.C
< prev
next >
Wrap
Text File
|
1991-08-30
|
29KB
|
787 lines
/*****************************************************************************/
/* */
/* ls - a Unix-like directory listing program for MS-DOS 2.x + */
/* */
/* 1984 R. Edward Nather */
/* 1985 Larry A. Shurr */
/* 1989 R. Ray Hensel Comverted to Microsoft V.5 */
/* cleaned up code */
/* added many coments */
/* replaced heap sort with quick sort */
/* */
/*****************************************************************************/
#include <stdio.h>
#include <dos.h>
char* malloc(); /*Assure that malloc() is char* type*/
typedef int bool; /*Define "boolean" type*/
typedef int mchar; /*Define "metachar" type*/
#define FALSE 0 /*Define "false" value*/
#define TRUE 1 /*Define "true" value*/
#define is == /*Define some readable stuff*/
#define isnot !=
#define and &&
#define or ||
/*****************************************************************************/
/* customizing constants */
#define NAMESIZ 13 /*12 character name + NULL*/
#define ONECS 512 /*cluster size on one-sided floppy*/
#define TWOCS 1024 /*cluster size on two-sided floppy*/
#define HARDCS 4096 /*cluster size on hard disk*/
#define SCRSIZ 22 /*scrolling size of display screen*/
/*****************************************************************************/
struct dta { /*DOS Disk Transfer Address table*/
char reserved[21]; /*used in "find next" operation*/
char attr; /*file attribute byte*/
unsigned ftime; /*time of last modification*/
unsigned fdate; /*date of last modification*/
long fsize; /*file size in bytes*/
char fname[NAMESIZ]; /*filename and extension*/
};
typedef struct dta DTA;
/*****************************************************************************/
struct outbuf { /*output buffer -- array of file info*/
unsigned oattr; /*file attributes*/
unsigned odate; /*file creation/modification date*/
unsigned otime; /*file creation/modification time*/
long osize; /*file size in bytes*/
char oname[NAMESIZ+1]; /*file name*/
} *obuf;
typedef struct outbuf OUTBUF;
/*****************************************************************************/
char spath[80]; /*holds current pathname string*/
mchar qs = '\\'; /*filename separator character*/
char dqs[] = "\\"; /*filename separator (string)*/
bool df_all = FALSE, /*1 => show hidden files by default*/
df_colm = FALSE, /*1 => 1-column listing by default*/
df_du = FALSE, /*1 => include disk use by default*/
df_id = FALSE, /*1 => always identify directory*/
df_long = FALSE, /*1 => long listing by default*/
df_more = FALSE, /*1 => pause for more*/
df_rsort = FALSE, /*1 => reverse sort by default*/
df_tsort = FALSE, /*1 => time sort by default*/
f_help = FALSE /*Help screen requested*/
;
/* global variables and flags */
int f_all, /*Include hidden & system files*/
f_colm, /*1-column format*/
f_du, /*Print disk usage*/
f_long, /*Long listing*/
f_rsort, /*Reverse sort*/
f_tsort, /*Timesort the listing*/
f_more = FALSE, /*Pause for more*/
f_recd = FALSE, /*Recursive descent requested*/
f_so = FALSE, /*Print sizes only*/
f_tsc = FALSE, /*Output is to console screen*/
np, /*number of groups printed*/
nargs, /*number of non-option arguments*/
clsize = 0, /*size of a cluster, in bytes*/
clmask, /*clsize-1 for rounding & chopping*/
drive /*code number for drive requested*/
;
long left, /*unused space left on disk*/
total /*total of sizes encountered*/
;
/*****************************************************************************/
main(argc, argv)
int argc;
char *argv[];
{
char *s
;
int c = 0,
nt = 0
;
setbuf(stdout,malloc(BUFSIZ)); /*Force standard output buffered*/
df_all = envbool("LSALL",df_all); /*1 => show hidden files by default*/
df_colm = envbool("LSCOLM",df_colm); /*1 => 1-column listing by default*/
df_du = envbool("LSDU",df_du); /*1 => include disk use by default*/
df_id = envbool("LSID",df_id); /*1 => always identify directory*/
df_long = envbool("LSLONG",df_long); /*1 => long listing by default*/
df_more = envbool("LSMORE",df_more); /*1 => pause for more*/
df_rsort = envbool("LSRSORT",df_rsort);/*1 => reverse sort by default*/
df_tsort = envbool("LSTSORT",df_tsort);/*1 => time sort by default*/
qs = envchar("LSQS",qs); /*Get default directory separator*/
dqs[0] = qs;
f_all = df_all; /*include hidden & system files*/
f_colm = df_colm; /*1-column format*/
f_du = df_du; /*print disk usage*/
f_long = df_long; /*long listing*/
f_more = df_more; /*pause for more*/
f_rsort = df_rsort; /*reverse sort*/
f_tsort = df_tsort; /*timesort the listing*/
f_recd = FALSE; /*recursive descent requested*/
f_so = FALSE; /*print sizes only*/
/* process input options */
while(--argc > 0 and (*++argv)[0] is '-') {
for(s = argv[0]+1; *s isnot '\0'; s++) {
switch(*s) {
case 'a': /*-a: list all files*/
f_all = !f_all;
break;
case 'c': /*-c: 1-column listing requested*/
f_colm = !f_colm;
break;
case 'h': /*-h: print help and quit*/
f_help = TRUE;
break;
case 'l': /*-l: long listing requested*/
f_long = !f_long;
break;
case 'm': /*-m: pause for more*/
f_more = TRUE;
break;
case 'r': /*-r: reverse sort direction*/
f_rsort = !f_rsort;
break;
case 's': /*-s: print sizes only*/
f_so = TRUE;
if (*(s+1) is '1') {
clsize = ONECS; /*diskuse for 1-sided floppy*/
s++;
nt++;
}
else if (*(s+1) is '2') {
clsize = TWOCS; /*or 2-sided*/
s++;
nt++;